#
# Copyright (c) 2011 CESNET
#
# LICENSE TERMS
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the Company nor the names of its contributors
#    may be used to endorse or promote products derived from this
#    software without specific prior written permission.
#
# ALTERNATIVELY, provided that this notice is retained in full, this
# product may be distributed under the terms of the GNU General Public
# License (GPL) version 2 or later, in which case the provisions
# of the GPL apply INSTEAD OF those given above.
#
# This software is provided ``as is'', and any express or implied
# warranties, including, but not limited to, the implied warranties of
# merchantability and fitness for a particular purpose are disclaimed.
# In no event shall the company or contributors be liable for any
# direct, indirect, incidental, special, exemplary, or consequential
# damages (including, but not limited to, procurement of substitute
# goods or services; loss of use, data, or profits; or business
# interruption) however caused and on any theory of liability, whether
# in contract, strict liability, or tort (including negligence or
# otherwise) arising in any way out of the use of this software, even
# if advised of the possibility of such damage.
#

PKGNAME = @PACKAGE_NAME@
TARGETS = netopeer-dm-manager

# Various configurable paths (remember to edit Makefile.in, not Makefile)
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@
bindir = @bindir@
includedir = @includedir@
libdir =  @libdir@
mandir = @mandir@

CC = @CC@
DOXYGEN = @DOXYGEN@
DOXYGEN_CONFIG = Doxyfile
DOXYGEN_DIR = doxygen
RPMBUILD = @RPMBUILD@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
RPMDIR = RPMBUILD
LIBS = $(patsubst -I.%,-I$(TOPDIR)/.%,$(patsubst -L.%,-L$(TOPDIR)/.%,$(filter -L% -I%,@LIBS@))) $(filter-out -L% -I%,@LIBS@)
CFLAGS = $(patsubst -I.%,-I$(TOPDIR)/.%,$(patsubst -L.%,-L$(TOPDIR)/.%,$(filter -L% -I%,@CFLAGS@))) $(filter-out -L% -I%,@CFLAGS@)
CPPFLAGS = $(patsubst -I.%,-I$(TOPDIR)/.%,$(patsubst -L.%,-L$(TOPDIR)/.%,$(filter -L% -I%,@CPPFLAGS@))) $(filter-out -L% -I%,@CPPFLAGS@)

OBJDIR= .obj
VERSION = $(shell cut -f1 @CONFIGURE_PWD@/VERSION | tr -d '\n')
TOPDIR = @CONFIGURE_PWD@

SRCS =  manager.c

HDRS = 

OBJS = $(SRCS:%.c=$(OBJDIR)/%.o)

all: $(TARGETS)

.PHONY: doc
doc: 

$(TARGETS): $(OBJS)
	@rm -f $@;
	$(CC) $(CFLAGS) $(CPPFLAGS) $(OBJS) $(LIBS) -o $@;

$(OBJDIR)/%.o: %.c
	@[ -d $$(dirname $@) ] || \
		(mkdir -p $$(dirname $@))
	$(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c $< -o $@

.PHONY: install
install: $(TARGETS)
	[ -d $(DESTDIR)/$(bindir) ] || \
	    (mkdir -p $(DESTDIR)/$(bindir); chmod 755 $(DESTDIR)/$(bindir))
	$(INSTALL_PROGRAM) $(TARGETS) $(DESTDIR)/$(bindir)/;

.PHONY: clean
clean:
	rm -rf $(TARGETS) $(OBJDIR)

.PHONY: tarball-prepare
tarball-prepare:
	@for i in Makefile.in $(SRCS) $(HDRS); do \
		[ -d $(TOPDIR)/$(PKGNAME)-$(VERSION)/$(shell pwd | xargs basename) ] || \
			mkdir -p $(TOPDIR)/$(PKGNAME)-$(VERSION)/$(shell pwd | xargs basename); \
		cp $$i $(TOPDIR)/$(PKGNAME)-$(VERSION)/$(shell pwd | xargs basename)/$$i; \
	done;
	
